<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片上传</title>
</head>
<body>
    <form id="uploadForm" enctype="multipart/form-data">
        <input type="file" name="image" id="imageInput" accept="image/*">
        <button type="button" onclick="uploadImage()">上传图片</button>
    </form>

    <script>
        function uploadImage() {
            var formData = new FormData(document.getElementById('uploadForm'));

            fetch('upload.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('图片上传成功！');
                    // 在此处可以将返回的相对地址存储到数据库
                    console.log(data.relativePath);
                } else {
                    alert('图片上传失败');
                }
            })
            .catch(error => console.error('Error:', error));
        }
    </script>
</body>
</html>
